﻿using CaltechSoft.Service.EntityFW.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CaltechSoft.Service.Repositories
{
    public class UserHistoryRepository : BaseRepository<UserHistory>, IUserHistoryRepository
    {
        public int Clear(DateTime? fromDate = null, DateTime? toDate = null)
        {
            int result = 0;
            if (fromDate.HasValue && toDate.HasValue)
            {
                var query = string.Format("DELETE FROM UserHistories WHERE LoginDate >= '{0}' AND LoginDate <= '{1}'",
                    fromDate.Value.ToString("yyyy-MM-dd"),toDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));

                result = Context.Database.ExecuteSqlCommand(query);
            }
            else
            {
                result = Context.Database.ExecuteSqlCommand("TRUNCATE TABLE UserHistories");
            }

            return result;
        }
    }
}
